type {{classname}}
{{#mappedModels}}
    {{#-first}}={{/-first}}{{^-first}}|{{/-first}} {{modelName}}Type {{modelName}}
{{/mappedModels}}


decoder : Decoder {{classname}}
decoder =
    Decode.field "{{{discriminator.propertyName}}}" Decode.string
        |> Decode.andThen {{classVarName}}Decoder


{{classVarName}}Decoder : String -> Decoder {{classname}}
{{classVarName}}Decoder tag =
    case tag of
{{#mappedModels}}
        "{{mappingName}}" ->
            Decode.map {{modelName}}Type {{modelName}}.decoder

{{/mappedModels}}
        _ ->
            Decode.fail <| "Trying to decode {{classname}}, but {{{discriminatorName}}} " ++ tag ++ " is not supported."


encode : {{classname}} -> Encode.Value
encode model =
    case model of
{{#mappedModels}}
        {{modelName}}Type subModel ->
            {{modelName}}.encode "{{mappingName}}" subModel

{{/mappedModels}}


toString : {{classname}} -> String
toString =
    Encode.encode 0 << encode
